<div  style ="margin-left: 100px;">
<?php
$errorsMessages =$this->form->getMessages();
//echo "<pre>"; var_dump($errorsMessages ); echo "</pre>";
foreach($errorsMessages as$message):
	foreach($message as $each_msg):
		echo $each_msg."<br/>";
	endforeach;
endforeach;

echo $this->form;
?>
</div>
<script type="text/javascript">
$(function()
{
    $("input").blur(function()
    {
        var formElementId = $(this).parent().prev().find('label').attr('for');

        doValidation(formElementId);
    });
});

function doValidation(id)
{
    var url = '<?php echo BASE_URL?>register/ajax-valid'
    var data = {};
    
        data[id] = $('#'+id).val();
    
    $.post(url,data,function(resp)
    {
        $("#"+id).parent().find('.errors').remove();       
        $("#"+id).parent().append(getErrorHtml(resp[id], id));
        //alert(resp[id]);
    },'json');
}

function getErrorHtml(formErrors , id)
{
    var o = '<ul id="errors-'+id+'" class="errors">';
    for(errorKey in formErrors)
    {
        o += '<li>' + formErrors[errorKey] + '</li>';
    }
    o += '</ul>';
    return o;
}

</script>